package com.teach.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.teach.dto.NewsSearch;
import com.teach.entity.News;

public interface NewsMapper {
    int deleteByPrimaryKey(Long newsId);

    int insert(News record);

    int insertSelective(News record);

    News selectByPrimaryKey(Long newsId);

    int updateByPrimaryKeySelective(News record);

    int updateByPrimaryKeyWithBLOBs(News record);

    int updateByPrimaryKey(News record);
    
    /**
     * 返回有搜索条件的所有记录
     * @param search
     * @return
     */
    List<News> select(NewsSearch search);
    
    /**
     * 按作者查询文章
     */
   @Select("select * from news where NEWS_CLASS_ID=6 and NEWS_STATUS=2 and NEWS_MANAGER = #{newsWorker} ORDER BY NEWS_TIME desc")
   List<News> selectByNewsWorker(@Param("newsWorker")String newsWorker);
   
   /**
    * 新闻首页轮播图
    */
   @Select("SELECT * from news where NEWS_CLASS_ID!=6 and NEWS_STATUS=2 and NEWS_TIME BETWEEN '2019-01-01' and NOW() ORDER BY RAND() LIMIT 3")
   List<News> select1();
   

   List<News> selectAdmin(NewsSearch search);

   /**
   
    */
   @Select("select * from (select * from news where NEWS_CLASS_ID!=6 and NEWS_STATUS=2 and NEWS_TIME BETWEEN '2019-01-01' and NOW() and NEWS_IMGS IS NOT NULL order by NEWS_TIME DESC) a GROUP BY NEWS_CLASS_ID")
   List<News> select2();
   /**
    * 按标题查询文章
    */
  @Select("select * from news where NEWS_TITLE = #{newsTitle}")
  News selectByTitle(@Param("newsTitle")String newsTitle);
  
  @Select("SELECT COUNT(*) FROM news WHERE NEWS_TITLE=#{newsTitle}")
  Long countByTitle(@Param("newsTitle")String newsTitle);
}
